"use strict";

const Controller = require("egg").Controller;

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = "hi, egg";
  }
  // 获取数据
  async getList() {
    const { ctx } = this;
    let sql = `select*from agent`;
    let data = await this.app.mysql.query(sql);
    ctx.body = { data };
  }
  // 删除数据
  async del() {
    const { ctx } = this;
    let { id } = ctx.query;
    let sql = `delete from agent where id=${id}`;
    let data = await this.app.mysql.query(sql);
    ctx.body = { data };
  }
  // 添加数据
  async add() {
    const { ctx, app } = this;
    const result = await app.mysql.insert("agent", {
      ...ctx.request.body,
    });
    ctx.body = result;
  }
  // 编辑数据
  async edit() {
    const { ctx, app } = this;
    const result = await app.mysql.update("agent", {
      ...ctx.request.body,
    });
    ctx.body = result;
  }

  // 运营获取数据
  async yunList() {
    const { ctx } = this;
    let sql = `select*from yunying`;
    let data = await this.app.mysql.query(sql);
    ctx.body = { data };
  }
  // 运营删除数据
  async yundel() {
    const { ctx } = this;
    let { id } = ctx.query;
    let sql = `delete from yunying where id=${id}`;
    let data = await this.app.mysql.query(sql);
    ctx.body = { data };
  }
  // 运营添加数据
  async yunadd() {
    const { ctx, app } = this;
    const result = await app.mysql.insert("yunying", {
      ...ctx.request.body,
    });
    ctx.body = result;
  }
  // 运营编辑数据
  async yunedit() {
    const { ctx, app } = this;
    const result = await app.mysql.update("yunying", {
      ...ctx.request.body,
    });
    ctx.body = result;
  }

  // 佣金获取数据
  async setList() {
    const { ctx } = this;
    let sql = `select*from blogs`;
    let data = await this.app.mysql.query(sql);
    ctx.body = { data };
  }

  // 会员获取数据
  async huiList() {
    const { ctx } = this;
    let sql = `select*from huiyuan`;
    let data = await this.app.mysql.query(sql);
    ctx.body = { data };
  }
}

module.exports = HomeController;
